package bdz.projects.sc
{
	
	import flash.display.Sprite;
	import flash.events.*;
	import bdz.projects.sc.events.*;
	/**
	 * ...
	 * @author ...
	 */
	public class KeyResolver extends Sprite
	{
		
		public static const CLASSIC:String = "classic";
		public static const STANDARD:String = "standard";
		public static const GRID:String = "grid";
		public static const GRID_LEFT:String = "gridleft";
		function KeyResolver() {
			addEventListener(Event.ADDED_TO_STAGE, initializeComponent);
		}
		protected function initializeComponent(evt:Event):void {
			stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyActivation);
		}
		protected function onKeyActivation(evt:KeyboardEvent):void {
			if (evt.ctrlKey) {
				if(evt.charCode != 0){
					dispatchEvent(new SCEvent(SCEvent.CONTROL_GROUP_SELECT, { key:String.fromCharCode(evt.charCode) } ));
				}
				return;
			}
			if (evt.keyCode == 27) {
				dispatchEvent(new SCEvent(SCEvent.CANCELLED));
				return;
			}
			dispatchEvent(new SCEvent(SCEvent.KEY_PRESS, { key:String.fromCharCode(evt.charCode) } ));			
		}
		
	}
	
}